home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / bin / register-module < prev    next >
Text File  |  2009-04-28  |  2KB  |  84 lines

  1. #!/bin/sh
  2. QUEUE=/var/lib/register-module
  3. BLACKLIST=0
  4. ADD_TO_INITRD=0
  5. TYPE=options
  6. PARAMS_ONLY=0
  7. ADD_PARAMS=1
  8.  
  9. if [ "$1" = "-b" ]; then
  10.     BLACKLIST=1
  11.     shift 1
  12. fi
  13. if [ "$1" = "-i" ]; then
  14.     ADD_TO_INITRD=1
  15.     shift 1
  16. fi
  17. if [ "$1" = "-t" ]; then
  18.     TYPE=$2
  19.     shift 2
  20. fi
  21. if [ "$1" = "-p" ]; then
  22.     PARAMS_ONLY=1
  23.     shift 1
  24. fi
  25. if [ "$1" = "-a" ]; then
  26.     ADD_PARAMS=1
  27.     shift 1
  28. fi
  29.  
  30. MODULE=$1
  31. shift
  32. PARAMS="$@"
  33.  
  34. BLACKLISTFILE=$QUEUE/$MODULE.blacklist
  35. LOADFILE=$QUEUE/$MODULE.load
  36. INITRDFILE=$QUEUE/$MODULE.initrd
  37. PARAMFILE=$QUEUE/$MODULE.params
  38.  
  39. if [ -d /etc/modprobe.d ] && [ ! -e /etc/modprobe.conf ]; then
  40.     MODPROBE_OPT=/etc/modprobe.d/local.conf
  41.     MODPROBE_BL=/etc/modprobe.d/blacklist.local.conf
  42. else
  43.     MODPROBE_OPT=/etc/modprobe.conf
  44.     MODPROBE_BL=/etc/modprobe.conf
  45. fi
  46.  
  47. mkdir -p $QUEUE
  48. if [ "$BLACKLIST" = 1 ]; then
  49.     touch $BLACKLISTFILE
  50.     echo "blacklist $MODULE" >> $MODPROBE_BL
  51.     exit 0
  52. fi
  53.  
  54. if [ "$PARAMS_ONLY" = 0 ]; then
  55.     if [ "$ADD_TO_INITRD" = 1 ]; then
  56.         touch $INITRDFILE
  57.     else
  58.         touch $LOADFILE
  59.     fi
  60. fi
  61.  
  62. if [ -n "$PARAMS" ]; then
  63.     if [ -e "$PARAMFILE" ]; then
  64.         if [ "$ADD_PARAMS" = 1 ]; then
  65.             PARAMS="$(grep "^$TYPE:" $PARAMFILE 2>/dev/null | sed "s/^$TYPE:\(.*\)$/\1/") $PARAMS"
  66.         fi
  67.         grep -v "^$TYPE:" $PARAMFILE > $PARAMFILE.new
  68.         mv $PARAMFILE.new $PARAMFILE
  69.     fi
  70.     echo "$TYPE:$PARAMS" >> $PARAMFILE
  71.  
  72.     if [ "$TYPE" = options ]; then
  73.         for file in /etc/modules.conf $MODPROBE_OPT; do
  74.             if [ -e "$file" ]; then
  75.                 grep -v "options $MODULE " $file > $file.new
  76.                 mv $file.new $file
  77.             else
  78.                 touch $file
  79.             fi
  80.             echo "options $MODULE $PARAMS" >> $file
  81.         done
  82.     fi
  83. fi
  84.